package com.warmlight.voicepacket.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.UMShareAPI;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.utils.StatusBarUtil;
import com.warmlight.voicepacket.utils.ToastUtil;

import butterknife.ButterKnife;

public class BaseActivity extends AppCompatActivity {

    //public static final String TAG = getThis().get

    public Activity getThis(){
        return this;
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }


    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }


    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);

        ButterKnife.bind(this);
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);

        ButterKnife.bind(this);
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        ButterKnife.bind(this);
    }

    // Toast出Msg
    protected void showToast(String msg) {
        ToastUtil.showShort(this, msg);
    }

    public Activity getContext(){
        return this;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    //公共设置
    public void setTitle(String title){
        TextView titleView = (TextView) findViewById(R.id.tv_title);
        titleView.setText(title);
    }

    public void setBack(){
        LinearLayout back = (LinearLayout) findViewById(R.id.ll_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                backClick();
                finish();
            }
        });
    }

    public void setBackShow(boolean isShow){
        LinearLayout back = (LinearLayout) findViewById(R.id.ll_back);
        if (isShow){
            back.setVisibility(View.VISIBLE);
        }else{
            back.setVisibility(View.INVISIBLE);
        }
    }

    public void showTitleBottomLine(boolean isShow){
        ImageView line = (ImageView) findViewById(R.id.iv_title_line);
        if (isShow){
            line.setVisibility(View.VISIBLE);
        }else{
            line.setVisibility(View.GONE);
        }
    }

    public void setRightText(String text){
        LinearLayout ll_right = (LinearLayout) findViewById(R.id.ll_right);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);
        ll_right.setVisibility(View.VISIBLE);
        tv_right.setVisibility(View.VISIBLE);
        tv_right.setText(text);
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rightTextClick();
            }
        });
    }

    public void rightTextClick(){

    }

    public void backClick(){

    }

}
